package ar.edu.unsam.algo3.plantasvszombies.ui.windows

import ar.edu.unsam.algo3.plantasvszombies.ui.ApplicationModels.FilaAppModel
import org.uqbar.arena.layout.HorizontalLayout
import org.uqbar.arena.layout.VerticalLayout
import org.uqbar.arena.widgets.Button
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.windows.WindowOwner
import org.uqbar.arena.bindings.NotNullObservable

class ObtenerPlantaWindow extends JardinZenWindow {

	new(WindowOwner parent, FilaAppModel unaFilaAppModel) {
		super(parent, unaFilaAppModel.fila.jardinZen)
		modelObject.jardinZen = unaFilaAppModel.fila.jardinZen
		modelObject.filaAppModel = unaFilaAppModel
		modelObject.actualizar //Corre este método cuando se crea la ventana
	}

	override def createMainTemplate(Panel mainPanel) {
		title = "Plantas disponibles"
		taskDescription = "Seleccione la planta de su preferencia"

		super.createMainTemplate(mainPanel)
	}

	override createTblPanel(Panel mainPanel) {

		val tblPanel = new Panel(mainPanel).setLayout(new VerticalLayout)
		createResultsGrid(tblPanel)

	}

	override protected addActions(Panel actionsPanel) {
		actionsPanel.setLayout(new HorizontalLayout)
		val btnAceptar = new Button(actionsPanel).setCaption("Aceptar").onClick[|this.accept].setAsDefault.disableOnError
		btnAceptar.bindEnabled(new NotNullObservable("plantaSeleccionada"))
		new Button(actionsPanel).setCaption("Cancelar").onClick[|this.close]

	}

	override def executeTask() {
		modelObject.filaAppModel.plantaElegida = modelObject.plantaSeleccionada
		super.executeTask()
	}

}
